package com.aaa.web.controller.employeecontroller;

import com.aaa.entity.Per;
import com.aaa.web.commons.EmpQuery;
import com.aaa.entity.Employee;
import com.aaa.web.commons.Result;
import com.aaa.web.service.iemployeeservice.IEmployeeService;
import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.request.AlipayTradeWapPayRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
/**
 * @program: battery
 * @description: 员工管理
 * @author:
 * @create:
 **/
@Controller
@RequestMapping("/emp")
public class EmployeeController {

    public static String APPID = "2016092400582812";
    public static String CHARSET = "UTF-8";
    public static String RSA_PRIVATE_KEY = "MIIEwAIBADANBgkqhkiG9w0BAQEFAASCBKowggSmAgEAAoIBAQCbqAijXUbpM1PKKO7dLq4En4E5gix8g0BeEZfvkEy+5vB6uYt9R+TFB12b/2RU5knmA1ZMgVzZLp4l20mwh50fgq2H6H2fQ92d08Vte1QXfQ18Y4H1L6d3NMEvAxeid7UiqbjFc4uy0RiJkFecc8L98pa5djFgZzjM2la2WqTYaGHINTZSdkFHcZV2PdPAOruLlRwT8QVVCKEXFLB7aZRh9Xw9RF2Vc2/v9bHdSRKs0r0EcJTUluzZGgT6Pa5YoDbSFntquu5e2tyCpICxqvR6ofxSU4fZhYFqCMpkIDic5zNyYPnPtKcFDcgBkTuVEp7Rl/fSaTeuEaNFPNiVWCkpAgMBAAECggEBAJMHsUkm5cGH80DFU4PoAQZq6HS7Cmx+ykFRGxR2WJgGqucx9pnbXDPklj6xikNL2EgFpPHVTC/2Afq+Xaf7IabPG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TKHNIfe7FSt0/bDJa+Yezh2weDaY3VwvOfH7XkSa7RaGw/llj08=";
    public static String ALIPAY_PUBLIC_KEY = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0uHmUq8w8s+RzUyXD33fZXMVE3muv1e/LT8XAcJ2Sbr8w/liXP4a4juqZwfa4bEgex3O7rhlqCEOuWAmGS8dqmblDf+6cVu9pXj0zy9wi1w+k3Vtn7KwL3tME4V+9FF4GYML3/4cF4dN2UtyfncQzRz2N86AN75D0I/GoGPl4u2Amhdj46ZhWL7twfyudJA4aMmMScDv9ZR6Sm3/lpwmn5sN/Z2N06VXCZd13hnqWE67XcN6jG5kd1QMYP0PAJHpeSfXd7i8GeV8z448H9rWGlXu+V/ScSQxSmWKDI1f0YwSM34Gkr+NyrymBCc4nXn95OCsc5zltO/laic/40BC4wIDAQAB+V9JilLqSa7N7sVqwpvv8zWChgXhX/A96hEg97Oxe6GKUmzaZRNh0cZZ88vpkn5tlgL4mH/dhSr3Ip00kvM4rHq9PwuT4k7z1DpZAf1eghK8Q5BgxL88d0X07m9X96Ijd0yMkXArzD7jg+noqfbztEKoH3kPMRJC2w4ByVdweWUT2PwrlATpZZtYLmtDvUKG/sOkNAIKEMg3Rut1oKWpjyYanzDgS7Cg3awr1KPTl9rHCazk15aNYowmYtVabKwbGVToCAGK+qQ1gT3ELhkGnf3+h53fukNqRH+wIDAQAB";
    @Autowired
    private IEmployeeService employeeService;

    /**
     * 员工管理页面
     * @param id
     * @param model
     * @return
     */
    @RequestMapping("/getEmpPage")
    public String getEmpPage(Integer id,Model model){
        model.addAttribute("schoolid",id);
        return "views/webhtml/employee/employee-list";
    }

    /**
     * 获取所有员工
     * @param query
     * @param id
     * @return
     */
    @RequestMapping("/getEmp")
    @ResponseBody
    public Map getAllEmployee(EmpQuery query,Integer id) {
        Map m = employeeService.getAllEmployee(query,id);
        return m;
    }

    /**
     * 获取某个员工信息
     * @param telephone
     * @return
     */
    @RequestMapping("/getEmpById")
    @ResponseBody
    public Employee getEmployeeById(String telephone){
      Employee emp = employeeService.getEmployeeById(telephone);
      return emp;
    }

    /**
     * 获取当前员工拥有的角色
     * @param id
     * @return
     */
    @RequestMapping("/getAllRole")
    @ResponseBody
    public List<Per> getAllRole(Integer id) {
        List<Per> m = employeeService.getAllRole(id);
        return m;
    }

    /**
     * 更新当前员工拥有的角色
     * @param array
     * @param id
     * @return
     */
    @RequestMapping("/updateRole")
    @ResponseBody
    public Result updateRole(int[] array,Integer id) {
        Result result = employeeService.updateRole(array,id);
        return result;
    }

    /**
     * 更新员工信息
     * @param emp
     * @return
     */
    @RequestMapping("/updateEmp")
    @ResponseBody
    public Result updateEmp(Employee emp) {
        Result result = employeeService.updateEmp(emp);
        return result;
    }

    /**
     * 添加员工
     * @param emp
     * @return
     */
    @RequestMapping("/addEmp")
    @ResponseBody
    public Result addEmp(Employee emp) {
        Result result = employeeService.addEmp(emp);
        return result;
    }

    /**
     * 更新员工状态
     * @param emp
     * @return
     */
    @RequestMapping("/updateEmpState")
    @ResponseBody
    public Result  updateEmpState(Employee emp) {
        Result result = employeeService.updateEmpState(emp);
        return result;
    }




}
